#ifndef CMESH_H
#define CMESH_H

// STD
#include <vector>
#include <string>

/*** ***/
#include <QtOpenGL>
#include "cpoint3f.h"
#include "cvecteur3f.h"

// PROJECT
#include "cvertex.h"
#include "cedge.h"
#include "cface.h"
#include "cdrawable.h"
#include "craytracable.h"
#include "csphere.h"

class CMesh : public CDrawable, public CRayTracable
{
public:
	CMesh();
	~CMesh();

	bool					LoadOBJ(const char *);
	bool					LoadOBJ(std::string);
	bool					SaveOBJ(char *);
	bool					SaveOBJ(std::string);
	void					makeCopyOf(CMesh *);
	void					computeNormals();
	void					computeEdges();
	void					pairEdges();
	void					checkVerticesNormals();

	void					normalizeSize();

	bool					isBuilt();
	bool					doesEdgeExist(CVertex*, CVertex *);
	CEdge *					getEdgeFromVertices(CVertex*, CVertex *);
	int						findIndOfVertex(CVertex*);

	CVertex *				getVertexByPos(CPoint P);

	void					clearAllList();
	void					clearVertexList();
	void					clearEdgeList();
	void					clearFaceList();


	void					paint();
	void					setupAllBS();


	//Return true if at least one intersection point actually exists
	//and then set the point to the first of these points and
	//the vector to the normal at this point, return false otherwise
	bool intersect(CRay * Ray, CPoint3f& P, CVecteur3f& V);
	void setMaterial(CMaterial mat);

    std::vector<CVertex*>   m_VertexList;
	std::vector<CEdge*>		m_EdgeList;
	std::vector<CFace*>		m_FaceList;

	CSphere *				BS;
protected:

	bool					m_bVerticesNormals;
	bool					m_bBuilt;
};

#endif // CMESH_H
